<?php

/**
 * Simple cross-domain AJAX proxy implementation.
 * To succeed any content delivering it uses BASE64 encoding mechanism
 * to transport data from a read remote file to a JavaScript variable.
 * Then it decoded into a normal content internally with JavaScrtipt
 * itself. Any way on a client side content will looks the same as it was
 * just opened with a standard methods.
 * 
 * @author  Mykhailo Stadnyk <mikhus@gmail.com>
 * @version 1.0
 */
if (!$_GET) exit;

$varname = @$_GET['__jsl_proxy_var__'];
$url     = @$_GET['__jsl_proxy_url__'];

/**
 * TODO: implement authentication support
 */
$user    = @$_GET['__jsl_user__'];
$pass    = @$_GET['__jsl_pass__'];

$content = (string) @file_get_contents( $url);

$content = base64_encode( $content);

$out .= "try { var $varname = Jsl.base64Decode( '$content'); } catch (e) {}\n";

header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT');
header( 'Accept-Ranges: bytes');
header( 'Content-Length: ' . strlen( $out));
header( 'Content-Type: application/javascript');

echo $out;
